<template>
	<view>
		<!-- 搜索框 -->
		<search @searchClickFn='searchClickFn'></search>
		<!-- 轮播图 -->
		<swiper :interval="3000" :duration="1000" autoplay circular indicator-dots>
			<swiper-item v-for="(item,i) in swiperData" :key="i">
				<navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`" class="swiper-item">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 菜单导航 -->
		<view class="nav-list">
			<view @click="navClickHandler(item)" v-for="(item,index) in cateList" :key="index" class="nav-item">
				<image :src="item.image_src" mode="widthFix"></image>
				<view></view>
			</view>
		</view>
		<!-- 楼层 -->
		<view class="floor_list">
			<view class="floor_item" v-for="(item,index) in floorList" :key="index">
				<!-- 标题 -->
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<!-- 内容 -->
				<view class="image_box">
					<view class="left_image_box">
						<navigator :url="item.product_list[0].url">
							<image :src="item.product_list[0].image_src"
								:style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
					<view class="right_image_box">
						<navigator v-for="(item2,index2) in item.product_list" :key="index2" v-if="index2 !=0"
							:url="item2.url">
							<image :src="item2.image_src" :style="{width: item2.image_width + 'rpx'}" mode="widthFix">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperData: [], //轮播图数据
				cateList: [], //菜单导航数据
				floorList: [], //楼层数据
			}
		},
		methods: {
			// 获取轮播图数据
			async getSwiperdata() {
				let {
					data
				} = await uni.$http.get('/home/swiperdata')

				if (data.meta.status !== 200) return uni.$showMsg()
				this.swiperData = data.message
			},
			// 获取菜单导航数据
			async getCateList() {
				let {
					data
				} = await uni.$http.get('/home/catitems')
				if (data.meta.status !== 200) return uni.$showMsg()
				this.cateList = data.message
			},
			// 菜单栏点击事件
			navClickHandler(item) {
				console.log(item);
				if (item.name == "分类") {
					//  跳转到分类TabBar页面
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorList() {
				let {
					data
				} = await uni.$http.get('/home/floordata')
				if (data.meta.status !== 200) return uni.$showMsg()
				//处理返回的数据
				data.message.forEach(item => {
					item.product_list.forEach(item1 => {
						item1.url = '../../subpkg/goods_list/goods_list?' + item1.navigator_url.split(
							'?')[1]
					})
				})
				this.floorList = data.message
			},
			//点击搜索框
			searchClickFn() {
				uni.navigateTo({
					url: `../../subpkg/search/search`
				})
			}
		},
		onLoad() {
			//请求轮播图数据
			this.getSwiperdata()
			//请求菜单导航数据
			this.getCateList()
			// 获取楼层数据
			this.getFloorList()
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			height: 100%;
			width: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 24rpx 0;

		.nav-item image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor_list {
		.floor_item {
			.floor-title {
				width: 100%;
				height: 62rpx;
			}
		}
	}

	.image_box {
		display: flex;

		.left_image_box {
			margin-left: 8rpx;
		}

		.right_image_box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
		}
	}
</style>